<link rel="stylesheet" href="${request.contextPath}/css/suredy-tree.css">
<div class="container-fluid suredy-form" style="padding-top: 0">
	<div class="row">	
	<form name="form" id="form">
		<input type="hidden" readonly="readonly" id="parentId" name="parentId" value="" />
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">父节点</div>
				<input type="text" class="form-control" readonly="readonly" id="parentName" value="" />
				<div class="input-group-addon btn btn-default btn-load-menu-tree" data-toggle="collapse" href="#menu-tree" aria-expanded="false" aria-controls="menu-tree">
					<i class="icon-sitemap"></i>
				</div>
			</div>
		</div>
		<div class="collapse" id="menu-tree" style="border-top:1px solid #ddd; max-height:300px; overflow:auto;">
			<div class="suredy-tree normal menu-tree-for-parent" data-uri="menu-tree.do">加载中……</div>
		</div>
		<div class="row">&nbsp;</div>


		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">菜单文本</div>
				<input type="text" class="form-control" id="text" name="text" placeholder="菜单文本" />
			</div>
		</div>
	
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">链接地址</div>
				<input type="text" class="form-control" id="url" name="url" placeholder="链接地址" />
			</div>
		</div>	
		
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">显示顺序</div>
				<input type="text" class="form-control" id="sort" name="sort" placeholder="显示顺序,默认0"/>
			</div>
		</div>	
		
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">菜单图标</div>
				<input type="text" class="form-control" id="icon" name="icon" placeholder="菜单图标"/>
			</div>
		</div>	
		
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">是否活动</div>
				<select class="form-control" id="active" name="active">
					<option value="true">是</option>
					<option value="false" selected="selected">否</option>
				</select>
			</div>
		</div>			

		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">是否收拢</div>
				<select class="form-control" id="collapse" name="collapse">
					<option value="true">是</option>
					<option value="false" selected="selected">否</option>				
				</select>
			</div>
		</div>	
	
							
		<div class="text-center">
			<div class="btn btn-info" id="btn-save" >
				<i class="icon-save"></i> 保存
			</div>
		</div>	
	</form>	
	</div>
</div>
<script src="${request.contextPath}/js/suredy-tree.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		var parentTree = function() {
			$('.menu-tree-for-parent').tree('menu/tree', {
				click : function() {
					$('#parentName').val($(this).text());
					var nodeData = $.suredy.tree.data($(this));
					
					
					if (nodeData.id) {
						$('#parentId').val(nodeData.id);
					} else {
						$('#parentId').val('');
					}
					
				}
			});
		};

		parentTree();
		

		
		$('#btn-save').click(function() {
			var text = $('#text').val();

			if (text == '') {
				alert('请填写名称！');
				return;
			}

	
			$.ajax({
				url : 'menu/create-save.do',
				dataType : 'json',
				type : 'POST',
				data : $('#form').serialize(),
				success : function(success) {
					if (!success) {
						alert('新建菜单失败！');
					} else if (!success.success) {
						alert('新建菜单失败！\n\n' + success.msg);
					} else {
						alert('新建菜单成功！');
						$.suredy.loadContent('menu/manager.do');
						$.suredy.closeModal();
					}
				},
				error : function(a, b, c) {
					alert('服务器错误! ' + b);
				}
			});
		});	
	});
</script>	
